import vueGlobal from '@gis/lib/vueGlobal.js';

export async function openInstructionFollowUpDialog({ id }) {
  return await new Promise((resolve) => {
    vueGlobal('$dialog', ($dialog) => {
      $dialog({
        content: () => import('./components/followUp.vue'),
        contentProps: { id },
        dialogProps: {
          title: '跟进',
          size: 'large',
          height: 'fixed',
          onOk: () => resolve(),
          onCancel: () => resolve(),
        },
      });
    });
  });
}

export function openInstructionFeedbackDialog({ id, onBeforeFeedback }) {
  return new Promise((resolve, reject) => {
    vueGlobal.get('$dialog')({
      content: () => import('./components/feedback.vue'),
      contentProps: { id, onBeforeFeedback },
      dialogProps: {
        title: '反馈',
        bodyStyle: { padding: '20px' },
        onOk: () => resolve(),
      },
    });
  });
}

export function openInstructionDetailsDialog({ title, id, canIReplay, canICloseCase, canIExportDetails }) {
  return new Promise((resolve, reject) => {
    vueGlobal.get('$dialog')({
      content: () => import('./components/instruction-details.vue'),
      contentProps: { id, canIReplay, canICloseCase, canIExportDetails },
      dialogProps: {
        width: 'large',
        height: 'fixed',
        title: title || '指令详情',
        footer: null,
        bodyStyle: { padding: 0 },
        /* 关闭弹窗刷新列表 */
        afterClose: () => resolve(),
        onOk: () => resolve(),
        onCancel: () => resolve(),
      },
    });
  });
}

//指令新增编辑 - 预警转指令：warnData
export function openInstructionAddUpdateDialog(option) {
  const { id, warnData, getContent } = Object.assign({}, option);
  return new Promise((resolve, reject) => {
    vueGlobal.get('$dialog')({
      content: () => import('./components/addUpdate.vue'),
      contentProps: { id, warnData, getContent },
      dialogProps: {
        title: (id ? '修改' : '新增') + '指令',
        width: 'large',
        height: 'fixed',
        bodyStyle: { padding: '20px' },
        /* 关闭弹窗刷新列表 */
        afterClose: () => resolve(),
        onOk: () => resolve(),
        onCancel: () => resolve(),
      },
    });
  });
}

export function openInstructionTemplateDialog({ contentProps }) {
  return new Promise((resolve, reject) => {
    vueGlobal.get('$dialog')({
      content: () => import('./components/instruction-template/index.vue'),
      contentProps: contentProps,
      dialogProps: {
        width: 'large',
        height: 'fixed',
        title: '选择模板',
        bodyStyle: { padding: '20px' },
        afterClose: () => resolve(),
        onOk: () => resolve(),
        onCancel: () => reject(),
      },
    });
  });
}

export function openInstructionTemplateAddEditDialog({ data }) {
  return new Promise((resolve, reject) => {
    vueGlobal.get('$dialog')({
      content: () => import('./components/instruction-template/AddEdit.vue'),
      contentProps: { data },
      dialogProps: {
        width: 'small',
        title: (data ? '修改' : '新增') + '模板',
        bodyStyle: { padding: '20px' },
        afterClose: () => resolve(),
        onOk: () => resolve(),
        onCancel: () => reject(),
      },
    });
  });
}
